package algorithm.niuke;

public class 行相等的最小多米诺翻转 {
    public int minDominoRotations(int[] A, int[] B) {
        int len = A.length;
        int[][] dp = new int[len][7];
        // 上
        dp[0][A[0]] = 0;
        dp[0][B[0]] = 1;
        for (int i = 1; i < len; i++) {
            int up = A[i];
            int down = B[i];
            dp[i][up] = dp[i - 1][up];
            if (up != down) {
                dp[i][down] = dp[i - 1][down] + 1;
            }
        }
        int minUp1 = dp[len - 1][A[0]];
        int minUp2 = dp[len - 1][B[0]];
        return minUp2;
    }

    public static void main(String[] args) {
        行相等的最小多米诺翻转 run = new 行相等的最小多米诺翻转();
        int[] a = { 2, 1, 2, 4, 2, 2 };
        int[] b = { 5, 2, 6, 2, 3, 2 };
        System.err.println(run.minDominoRotations(a, b));
    }
}
